import request from '@/utils/request'

const menuApi = process.env.VUE_APP_SYS_API + '/menu'

/**
 * 获取全部菜单 返回树
 * @param params
 * @returns {AxiosPromise}
 */
export const getTreeMenu = (params) => {
  return request({
    url: `${menuApi}/trees`,
    method: 'GET',
    params
  })
}

/**
 * 根据角色id获取菜单信息
 * @param roleId 角色id
 * @returns {AxiosPromise}
 */
export const getRoleMenuTree = (roleId) => {
  return request({
    url: `${menuApi}/roleMenuTree/${roleId}`,
    method: 'GET',
  })
}

/**
 * 单条查询菜单信息
 * @param id 菜单id
 * @returns {AxiosPromise}
 */
export const getMenuById = (id) => {
  return request({
    url: `${menuApi}/${id}`,
    method: 'GET',
  })
}

/**
 * 修改菜单
 * @param data 菜单数据
 * @returns {AxiosPromise}
 */
export const updateMenu = (data) => {
  return request({
    url: `${menuApi}/${data.id}`,
    method: 'PUT',
    data
  })
}

/**
 * 新增菜单
 * @param data 菜单数据
 * @returns {AxiosPromise}
 */
export const addMenu = (data) => {
  return request({
    url: `${menuApi}`,
    method: 'POST',
    data
  })
}

/**
 * 删除菜单
 * @param id 菜单id
 * @returns {AxiosPromise}
 */
export const delMenu = (id) => {
  return request({
    url: `${menuApi}/${id}`,
    method: 'DELETE'
  })
}

/**
 * 更改菜单状态
 * @param id 菜单id
 * @param status 菜单状态
 * @returns {AxiosPromise}
 */
export const changeMenuStatus = (id, status) => {
  let data = {
    id,
    status
  }
  return request({
    url: `${menuApi}/changeStatus`,
    method: 'PUT',
    data
  })
}
